package com.urms.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class MyDateTimeFormatting {
    public static String DateTimeFormatting(LocalDateTime inputTime) {
        LocalDateTime currentTime = LocalDateTime.now();
        String postDateTime;
        long daysBetween = ChronoUnit.DAYS.between(inputTime.toLocalDate(), currentTime.toLocalDate());
        if (daysBetween == 0) {
            postDateTime="今天"+ inputTime.format(DateTimeFormatter.ofPattern("HH:mm"));
        } else if (daysBetween == 1) {
            postDateTime="昨天"+inputTime.format(DateTimeFormatter.ofPattern("HH:mm"));
        } else if (daysBetween == 2) {
            postDateTime="前天"+inputTime.format(DateTimeFormatter.ofPattern("HH:mm"));
        } else {
            postDateTime = inputTime.format(DateTimeFormatter.ofPattern("MM-dd HH:mm")).toString();
        }
        return postDateTime;
    }
}
